/*
 * Translator.cpp
 *
 *  Created on: Nov 4, 2011
 *      Author: gonzalo
 */

#include "Translator.h"
#include "../DTOCliente.h"
#include "../DTOEvent.h"
#include "../DTOTankStatus.h"

DTO* Translator::translate(Event& event) {

//Entiendo que solo me interesa si son Quit, keyPressed o released

	switch (event.getType()) {
	case Quit:
		return new DTOCliente(event.getSender(), DISCONECTED);
		break;
	case KeyPressed:
		return event.transformInDTO();
		break;
	case KeyReleased:
		return event.transformInDTO();
		break;
	case UserEvent:
		return translateUserEvent(event);
		break;
	default:
		return NULL;
		break;
	}

	return NULL;

}

DTO* Translator::translateUserEvent(Event& event){
	switch (event.getEvent()->user.code) {
		case Tank_Status:
				return event.transformInDTOTankStatus();
			break;
		default:
			break;
	}

	return NULL;
}

Event* Translator::translate(DTO* dto) {

	if (dto == NULL) {
		return NULL;
	}


	switch (dto->getType()) {
		case EVENT:{
			DTOEvent* dtoevent = (DTOEvent*) dto;
			Event event(dtoevent);
			SDL_PushEvent(event.getEvent());
			return NULL;
			break;
		}
		case CLIENTE:{
				DTOCliente* dtoClient = (DTOCliente*)dto;
				Event event(dtoClient);
				SDL_PushEvent(event.getEvent());
				return NULL;
			break;
		}
		case TANK_STATUS:{
				DTOTankStatus* dtoTank= (DTOTankStatus*)dto;
				Event event(dtoTank);
				SDL_PushEvent(event.getEvent());
				return NULL;
			break;
		}
		default:{
				return NULL;
			break;
		}
	}

	return NULL;
}

std::list<ScenarioElement*> Translator::translateScenarioElementDTO(
		std::list<DTOScenarioElement*> elements) {
	std::list<ScenarioElement*> retorno;

	std::list<DTOScenarioElement*>::iterator it;
	for (it = elements.begin(); it != elements.end(); ++it) {
		retorno.push_back(new ScenarioElement((DTOScenarioElement*) (*it)));
	}

	return retorno;
}
